import matplotlib.pyplot as plt
from PIL import ImageFilter, Image, ImageEnhance
import numpy as np
### Применить 5 фильтров к своей фотке
path = 'photo.png'
img = plt.imread(path)
# great summary of Colormaps in Matplotlib can be found here
# https://matplotlib.org/stable/tutorials/colors/colormaps.html
print(img.shape)
(768, 1366, 3)
plt.imshow(img)
plt.axis('off')
plt.show()
## standard way
# 1st filter
plt.imshow(img.mean(2), cmap='magma')
plt.axis('off')
plt.show()
# 2nd filter
plt.imshow(img.mean(2), cmap='jet')
plt.axis('off')
plt.show()
# 3rd filter
plt.imshow(img.mean(2), cmap='seismic')
plt.axis('off')
plt.show()
# 4th filter
plt.imshow(img.mean(2), cmap='bone')
plt.axis('off')
plt.show()
# 5th filter
plt.imshow(img.mean(2), cmap='Set2')
plt.axis('off')
plt.show()
## PIL way
img = Image.open(path)
img
# 1st filter
img.convert('L')
# 2nd filter
img.filter(ImageFilter.SMOOTH)
# 3rd filter
img.filter(ImageFilter.GaussianBlur(radius=5))
# 4th filter
img.filter(ImageFilter.FIND_EDGES)
# 5th filter
enh = ImageEnhance.Sharpness(img)
enh.enhance(20.0)
### Сделать программу для поиска кружочков в изображении
import matplotlib.pyplot as plt
from PIL import ImageFilter, Image, ImageEnhance
import cv2
import numpy as np
img = cv2.imread('puzyrki.jpg')
imgc = img.copy()
#kernel = np.ones((10,10),np.uint8)
#blur = cv2.morphologyEx(imgc, cv2.MORPH_CLOSE, kernel)
gray_output = cv2.cvtColor(imgc, cv2.COLOR_BGR2GRAY)
circles = cv2.HoughCircles(gray_output,
cv2.HOUGH_GRADIENT,
dp=1,
param1 = 90,
param2 = 80,
minDist= 100,
minRadius=10,
maxRadius=500)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(img, (i[0], i[1]), i[2], (0, 255, 0), 2)
plt.imshow(img)
plt.axis('off')
plt.show()